package com.genius.adminmanager.user.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONObject;
import com.genius.adminmanager.other.entity.ResponseJson;
import com.genius.adminmanager.user.service.UserService;
import com.genius.workflow.log.ControllerLog;

@Controller
public class EditController {
	@Autowired
    @Qualifier("userEditorService")
    private UserService userEditorService;
	/**
	 * 跳转到新的编辑页面
	 * @param session
	 * @return
	 * @throws Exception
	 */
	@RequiresPermissions("a050ce3da4474dc2973fa413186fd1ca")
	@PostMapping("/adminmanager/user/toEdit")
	public String toEdit(){
		return "/views/adminmanager/user/edit";
	}
	
	/**
	 * 编辑操作
	 * @param session
	 * @return
	 * @throws Exception
	 */
	@ControllerLog(description="编辑用户")
	@PostMapping("/adminmanager/user/edit")
	@ResponseBody
	public JSONObject edit(@RequestBody JSONObject json){
		JSONObject response = new JSONObject();
    	response.put(ResponseJson.code, 0);
    	response = userEditorService.edit(json, response);
		return response;
	}
	@PostMapping("/adminmanager/user/photo_edit")
	public String photo_edit(){
		return "/views/adminmanager/user/photo_edit";
	}
	/**
	 * 编辑操作
	 * @param session
	 * @return
	 * @throws Exception
	 */
	@ControllerLog(description="编辑头像")
	@PostMapping("/adminmanager/user/update_photo")
	@ResponseBody
	public JSONObject update_photo(@RequestBody JSONObject json){
		JSONObject response = new JSONObject();
    	response.put(ResponseJson.code, 0);
    	response = userEditorService.update_photo(json, response);
		return response;
	}
	/**
	 * 编辑操作
	 * @param session
	 * @return
	 * @throws Exception
	 */
	@ControllerLog(description="重置密码")
	@PostMapping("/adminmanager/user/reset_password")
	@ResponseBody
	public JSONObject reset_password(@RequestBody JSONObject json){
		JSONObject response = new JSONObject();
    	response.put(ResponseJson.code, 0);
    	response = userEditorService.reset_password(json, response);
		return response;
	}
}
